package cn.yuhh.core.domain;

import cn.yuhh.core.type.Status;
import cn.yuhh.core.util.DateUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;

import java.io.Serializable;
import java.util.Date;

/**
 * @version 1.0
 * @desc: mongo实体父类
 * @author: DengZhaoBing
 * @create: 2019-09-05 14:22
 **/
public class Domain implements Serializable {

    @Id
    private String id;

    /**
     * 创建时间
     */
    private Long createAt = System.currentTimeMillis() / 1000;

    /**
     * 更新时间
     */
    private Long updateAt = System.currentTimeMillis() / 1000;

    /**
     * 数据状态
     */
    @Indexed
    private Status status = Status.ACTIVE;


    public Date getCreateTime() {
        return createAt == null ? null :  new Date(createAt * 1000);
    }

    public String getCreateTimeString() {
        Date createTime = getCreateTime();
        return createTime == null ? null : DateUtils.dateToString(createTime, "yyyy-MM-dd HH:mm:ss");
    }

    public String getCreateTimeShortString() {
        Date createTime = getCreateTime();
        return createTime == null ? null : DateUtils.dateToString(getCreateTime(), "yyyy-MM-dd");
    }

    public Date getUpdateTime() {
        return updateAt == null ? null :  new Date(updateAt * 1000);
    }

    public String getUpdateTimeString() {
        Date updateTime = getUpdateTime();
        return updateTime == null ? null : DateUtils.dateToString(updateTime, "yyyy-MM-dd HH:mm:ss");
    }

    public String getUpdateTimeShortString() {
        Date updateTime = getUpdateTime();
        return updateTime == null ? null : DateUtils.dateToString(getUpdateTime(), "yyyy-MM-dd");
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Long getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Long createAt) {
        this.createAt = createAt;
    }

    public Long getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Long updateAt) {
        this.updateAt = updateAt;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
